package com.moyq5.mvc.maker.test.bean.entity;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

/**
 * 金钱交易记录
 * @author Moyq5
 * @date 2018年4月27日
 */
@Entity
@Table(name = "tra_trade")
@DynamicUpdate
public class TraTrade implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 订单ID
	 */
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "native")@GenericGenerator(name = "native", strategy = "native")
    @Column(name = "trade_id")
	private Long tradeId;
	/**
     * 交易金额
     */
    @Column(name = "amount", nullable = false, precision = 10, scale = 2)
    private BigDecimal amount;
	/**
	 * 渠道手续费
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "channel_cost_id")
	private TraCost channelCost;
	/**
	 * (商家级)代理商手续费
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "agent_cost_id")
	private TraCost agentCost;
	/**
	 * 商家手续费
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "merch_cost_id")
	private TraCost merchCost;
	/**
	 * 添加时间
	 */
	@Column(name = "add_time", nullable = false, columnDefinition="datetime")
	private Date addTime;
	
	@PrePersist
	public void prePersist() {
		if (null == addTime) {
			addTime = new Date();
		}
	}

	public Long getTradeId() {
		return tradeId;
	}

	public void setTradeId(Long tradeId) {
		this.tradeId = tradeId;
	}

	public BigDecimal getAmount() {
		return amount;
	}

	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}

	public TraCost getChannelCost() {
		return channelCost;
	}

	public void setChannelCost(TraCost channelCost) {
		this.channelCost = channelCost;
	}

	public TraCost getAgentCost() {
		return agentCost;
	}

	public void setAgentCost(TraCost agentCost) {
		this.agentCost = agentCost;
	}

	public TraCost getMerchCost() {
		return merchCost;
	}

	public void setMerchCost(TraCost merchCost) {
		this.merchCost = merchCost;
	}

	public Date getAddTime() {
		return addTime;
	}

	public void setAddTime(Date addTime) {
		this.addTime = addTime;
	}
	
}
